import appium.webdriver
from config import Plat_Form_Version,App_Package,App_Activity,Appium_Remote_Url


'''
   获取driver 
'''
class GetDriver:
    __app_driver = None

    # 获取driver
    @classmethod
    def get_app_driver(cls):
        # 获取app driver
        if cls.__app_driver is None:
            # 设置启动
            desired_caps = {}
            # 必填-且正确
            desired_caps['platformName'] = 'Android'
            # 必填-且正确
            desired_caps['platformVersion'] = Plat_Form_Version
            # 必填
            desired_caps['deviceName'] = 'RFCR71NPQBT'
            # APP包名  com.yixian.pinball/com.incube.insave.ui.activity.SplashActivity
            desired_caps['appPackage'] = App_Package
            # 启动名
            desired_caps['appActivity'] = App_Activity
            # 设置中文
            desired_caps['unicodeKeyboard'] = True
            desired_caps['resetKeyboard'] = True
            # 配置 UiAutomator2 解决找不到元素的问题
            desired_caps['automationName'] = 'uiautomator2'
            # desired_caps['ANDROID_UIAUTOMATOR'] = 'uiautomator2'
            desired_caps['ignoreHiddenApiPolicyError'] = True
            # 不每次重置app
            desired_caps['noReset'] = True
            # 防止通信超时,20分钟
            desired_caps['newCommandTimeout'] = 1200
            # 设置driver
            cls.__app_driver = appium.webdriver.Remote(Appium_Remote_Url, desired_caps)
        return cls.__app_driver









